import { observable, computed, action, makeObservable } from 'mobx'
let userData = localStorage.getItem('user')
class user {
  constructor() {
    makeObservable(this)
  }
  @observable user = {
    data: userData ? JSON.parse(userData) : ''
  }
  @computed get getUser() {
   
    return this.user
  }
 
 
  @action userCommit(type,data){
    switch(type){
    case 'login' :
      this.user.data = data
      data = data ? JSON.stringify(data) : ''
      window.localStorage.setItem('user',data)
      break
    case 'exit':
      this.user.data=''
      localStorage.removeItem('user')
      break
      default :
        break
    }
    
    console.log(this.user)
  }


}
const userStore = new user()
export default userStore
